//主页控制层
package com.happy.Animation.controllers;

import com.happy.Animation.dao.*;
import com.happy.Animation.entities.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class HomeController {
    @Autowired
    CommentRepository commentRepository;

    @Autowired
    CountryRepository countryRepository;

    @Autowired
    ClassificationRepository classificationRepository;

    @Autowired
    AuthorRepository authorRepository;

    @Autowired
    ProjectRepository projectRepository;

    @GetMapping("/")
    public String displayHome(Model model){
        List<Project> projects = projectRepository.findAll();
        model.addAttribute("projects",projects);

        List<Author> authors = authorRepository.findAll();
        model.addAttribute("authors",authors);

        List<Country> countries = countryRepository.findAll();
        model.addAttribute("countries",countries);

        List<Classification> classifications = classificationRepository.findAll();
        model.addAttribute("classifications",classifications);

        List<Comment> comments = commentRepository.findAll();
        model.addAttribute("comments",comments);

        return "home/home";
    }
}
